﻿<%@ WebHandler Language="C#" Class="ContainerCombinateHandler" %>

/*Description: 批次组合处理程序
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer: Zhangrj 
'create Date:20230612
'Rewriter:
'Rewrite Date:
*/
using System;
using System.Web;
using BusinessRule.DTO;
using System.Web.SessionState;
using DatabaseAccess.DBUtility;
using System.Data.OracleClient;
using System.Data;
using Newtonsoft.Json;
using System.Collections.Generic;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;
using System.IO;
using System.Collections;
using System.Linq;
using System.Text;

public class ContainerCombinateHandler : IHttpHandler, IRequiresSessionState
{
    private static object obj = new object();
    CurrentUserInfo m_UserInfo;
    uLMSCommonBusiness commonBusiness = new uLMSCommonBusiness();
    uLMSContainerBusiness containerBusiness = new uLMSContainerBusiness();
    uLMSDispatchBusiness dispatchBusiness = new uLMSDispatchBusiness();
    uLMSWorkReportBusiness workReportBusiness = new uLMSWorkReportBusiness();
    uLMSCheckBusiness checkBusiness = new uLMSCheckBusiness();
    string toAppID_RB = System.Configuration.ConfigurationManager.AppSettings["ToAppID_RB"].ToString(); //数据中心推送目的ID（热表）

    public void ProcessRequest(HttpContext context)
    {
        try
        {
            m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
            if (m_UserInfo == null)
            {
                context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "数据过期，请重新登录" }));
                return;
            }
            var action = context.Request["action"].ToString();
            switch (action)
            {
                case "GetRBContainerCombinateDataList": //获取待合卡的数据列表（热表）
                    GetRBContainerCombinateDataList(context);
                    break;
                case "GetRBUnDispatchContainer": //获取未派工批次数据列表（热表）
                    GetRBUnDispatchContainerDataList(context);
                    break;
                case "GetRBDispatchContainer": //获取已派工但未报工批次数据列表（热表）
                    GetRBDispatchContainerDataList(context);
                    break;
                case "SaveContainerCombinateData": //保存合卡数据
                    SaveContainerCombinateData(context);
                    break;
                case "DeleContainerCombinateData": //删除合卡数据
                    DeleContainerCombinateData(context);
                    break;
                /*----------------工步撤销功能------------------------*/
                case "InitRBCombinateContainerCancel": //初始化合卡工步撤销页面
                    InitRBCombinateContainerCancel(context);
                    break;
                case "GetRBContainerCancelDetailList": //获取热表批次撤销明细数据（热表）
                    GetRBContainerCancelDetailList(context);
                    break;
                case "SaveStepInfoDispatchCancel": //删除工步派工数据
                    SaveStepInfoDispatchCancel(context);
                    break;
                case "SaveStepInfoWorkReportCancel": //删除工步报工数据
                    SaveStepInfoWorkReportCancel(context);
                    break;
                case "SaveStepInfoCheckCancel": //删除工步检验数据
                    SaveStepInfoCheckCancel(context);
                    break;
                case "GetRBContainerCombinateDetail": //获取合卡明细批次
                    GetRBContainerCombinateDetail(context);
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            uMESProcessResult result = new uMESProcessResult();
            result.Result = false;
            result.Message = ex.Message;
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }
    /// <summary>
    /// 初始化合卡工步撤销页面（热表）
    /// </summary>
    /// <param name="context"></param>
    public void InitRBCombinateContainerCancel(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true, ReturnData = "" };
        switch (GetRoleLimits())
        {
            case RoleEnum.全部:
                result.ReturnData = "[{\"showTab\":0},{\"showTab\":1},{\"showTab\":2}]";
                break;
            case RoleEnum.派工:
                result.ReturnData = "[{\"showTab\":0}]";
                break;
            case RoleEnum.报工:
                result.ReturnData = "[{\"showTab\":1}]";
                break;
            case RoleEnum.检验:
                result.ReturnData = "[{\"showTab\":2}]";
                break;
            case RoleEnum.无权限:
                result.Result = false; result.Message = "很抱歉，您没有权限";
                break;
            default:
                result.Result = false; result.Message = "未知权限";
                break;
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 角色权限枚举
    /// </summary>
    private enum RoleEnum { 全部, 派工, 报工, 检验, 无权限 }
    /// <summary>
    /// 获取当前用户角色权限
    /// </summary>
    /// <returns></returns>
    private RoleEnum GetRoleLimits()
    {
        if (m_UserInfo.Roles.Contains("系统管理员"))
        {
            return RoleEnum.全部;
        }
        else if (m_UserInfo.Roles.Contains("工区长"))
        {
            return RoleEnum.派工;
        }
        else if (m_UserInfo.Roles.Contains("工人"))
        {
            return RoleEnum.报工;
        }
        else if (m_UserInfo.Roles.Contains("检验员"))
        {
            return RoleEnum.检验;
        }
        else
        {
            return RoleEnum.无权限;
        }
    }
    /// <summary>
    /// 获取合卡批次明细（通过合卡名）
    /// </summary>
    /// <param name="context"></param>
    public void GetRBContainerCombinateDetail(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        string combinateName = context.Request["combinateName"].ToString();//合卡名
        result.DBTable = containerBusiness.GetCombinateContainerDetailByName(combinateName);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 获取热表批次撤销明细数据
    /// </summary>
    /// <param name="context"></param>
    public void GetRBContainerCancelDetailList(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        string containerName = context.Request["containerName"].ToString();//批次名
        string combinateName = context.Request["combinateName"].ToString();//合卡名
        if (!string.IsNullOrWhiteSpace(containerName) && !string.IsNullOrWhiteSpace(combinateName))
        {
            result.Result = false; result.Message = "查询条件不明确，批次名、合卡名不可同时查询";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        if (string.IsNullOrWhiteSpace(containerName) && string.IsNullOrWhiteSpace(combinateName))
        {
            result.Result = false; result.Message = "请输入查询条件";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        //查询批次信息
        DataTable dtContainer = new DataTable();
        if (!string.IsNullOrWhiteSpace(combinateName))
        {
            dtContainer = containerBusiness.GetCombinateContainerDetailByName(combinateName);
        }
        else
        {
            string containerSql = string.Format(@"SELECT c.containerid,c.containername,DECODE(c.isinstore,-1,cc.mfgworkflowid,0,c.workflowid,c.bsworkflowid) workflowid
                    ,c.mfgordername,c.productname,c.workflowname,c.qty,cc.originalstartdate createdate,c.isinstore,c.workflowstepname,
                    c.containertype,c.workflowstepid,'0' iscombinate
                    FROM containercurrentinfo c
                    LEFT JOIN container cc ON cc.containerid = c.containerid
                    WHERE c.containername = '{0}' AND c.containerstatus = 1 
                    AND NOT EXISTS(SELECT 1 FROM containercombinate cb WHERE cb.containerid = c.containerid)", containerName);
            dtContainer = DatabaseHelper.Query_ReturnDatTable(containerSql);
        }
        if (dtContainer.Rows.Count == 0)
        {
            result.Result = false; result.Message = "未查询到数据";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        if (dtContainer.AsEnumerable().Where(p => string.IsNullOrWhiteSpace(p["containerId"].ToString())).Count() > 0)
        {
            result.Result = false; result.Message = "未查询到数据";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        if (dtContainer.Select("isinstore = 1").Length > 0)
        {
            result.Result = false; result.Message = "批次已入库";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        //查询工步信息
        //DataTable dtStepInfo = commonBusiness.GetStepinfoByWorkflowID(dtContainer.Rows[0]["workflowid"].ToString());

        string containerId = dtContainer.Rows[0]["containerId"].ToString();
        string workflowStepId = dtContainer.Rows[0]["workflowstepid"].ToString();
        //派工信息
        DataTable dtDispatch = new DataTable();
        string disSql = @"SELECT csd.stepinfoid,csd.createdate,csd.qty,e.fullname,s.stepno,
        s.description,ws.workflowstepname,ws.workflowstepid,csd.containerstepdispatchid
        FROM containerstepdispatch2 csd 
        LEFT JOIN employee e ON e.employeeid = csd.employeeid
        LEFT JOIN workflowstep ws ON ws.workflowstepid =csd.workflowstepid
        LEFT JOIN stepinfo s ON s.stepinfoid = csd.stepinfoid
        WHERE csd.isuse = 0  AND csd.containerid = '{0}' and csd.workflowstepid = '{1}' 
        {2}
        ORDER BY ws.workflowstepid,s.stepseq";
        //报工信息
        DataTable dtWorkReport = new DataTable();
        string workSql = @"SELECT csw.stepinfoid,csw.createdate,csw.qty,e.fullname,s.stepno,
        s.description,ws.workflowstepname,ws.workflowstepid,csw.containerstepworkreportid
        FROM containerstepworkreport2 csw
        LEFT JOIN employee e ON e.employeeid = csw.workerid
        LEFT JOIN workflowstep ws ON ws.workflowstepid =csw.workflowstepid
        LEFT JOIN stepinfo s ON s.stepinfoid = csw.stepinfoid
        WHERE csw.isuse = 0  AND csw.containerid = '{0}' and csw.workflowstepid = '{1}' 
        {2}
        ORDER BY ws.workflowstepid,s.stepseq";
        //检验信息
        DataTable dtCheck = new DataTable();
        string checkSql = @"SELECT cci.stepinfoid,cci.checkqty,cci.acceptanceqty passqty,cci.lossqty,
        cci.createdate,e.fullname,s.stepno,s.description,ws.workflowstepname,ws.workflowstepid,s.stepseq,
        cci.containercheckinfoid,cci.containerstepworkreportid,c.containertype,c.containerid
        FROM containercheckinfo2 cci
        LEFT JOIN containercurrentinfo c ON c.containerid = cci.containerid
        LEFT JOIN employee e ON e.employeeid = cci.checkerid
        LEFT JOIN workflowstep ws ON ws.workflowstepid =cci.workflowstepid
        LEFT JOIN stepinfo s ON s.stepinfoid = cci.stepinfoid
        WHERE cci.isuse = 0  AND cci.containerid = '{0}' and cci.workflowstepid = '{1}' 
        {2}
        ORDER BY ws.workflowstepid,s.stepseq";
        //通过角色权限，显示相对应的数据
        switch (GetRoleLimits())
        {
            case RoleEnum.全部:
                dtDispatch = DatabaseHelper.Query_ReturnDatTable(string.Format(disSql, containerId, workflowStepId, ""));
                dtWorkReport = DatabaseHelper.Query_ReturnDatTable(string.Format(workSql, containerId, workflowStepId, ""));
                dtCheck = DatabaseHelper.Query_ReturnDatTable(string.Format(checkSql, containerId, workflowStepId, ""));
                break;
            case RoleEnum.派工:
                disSql = string.Format(disSql, containerId, workflowStepId, string.Format("AND csd.workcenterid='{0}'", m_UserInfo.WorkCenterID));
                dtDispatch = DatabaseHelper.Query_ReturnDatTable(disSql);
                break;
            case RoleEnum.报工:
                workSql = string.Format(workSql, containerId, workflowStepId, string.Format("AND csw.workerid='{0}'", m_UserInfo.EmployeeID));
                dtWorkReport = DatabaseHelper.Query_ReturnDatTable(workSql);
                break;
            case RoleEnum.检验:
                checkSql = string.Format(checkSql, containerId, workflowStepId, string.Format("AND cci.checkerid='{0}'", m_UserInfo.EmployeeID));
                dtCheck = DatabaseHelper.Query_ReturnDatTable(checkSql);
                break;
            case RoleEnum.无权限:
                result.Result = false; result.Message = "很抱歉，您没有权限";
                break;
            default:
                result.Result = false; result.Message = "未知权限";
                break;
        }
        if (result.Result)
        {
            dtContainer.TableName = "dtContainer";
            result.DBDataSet.Tables.Add(dtContainer);//批次
            dtDispatch.TableName = "dtDispatch";
            result.DBDataSet.Tables.Add(dtDispatch);//派工记录
            dtWorkReport.TableName = "dtWorkReport";
            result.DBDataSet.Tables.Add(dtWorkReport);//报工记录
            dtCheck.TableName = "dtCheck";
            result.DBDataSet.Tables.Add(dtCheck);//检验记录
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 保存工步派工撤销
    /// </summary>
    /// <param name="context"></param>
    public void SaveStepInfoDispatchCancel(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "撤销成功" };
        RoleEnum roleEnum = GetRoleLimits();
        if (!(roleEnum == RoleEnum.派工 || roleEnum == RoleEnum.全部))
        {
            result.Result = false; result.Message = "没有该权限";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        DataTable dtContainer = JsonConvert.DeserializeObject<DataTable>(context.Request["container"].ToString());
        DataTable dtParam = JsonConvert.DeserializeObject<DataTable>(context.Request["param"].ToString());
        DataTable dtDis = new DataTable();//推送数据中心更改数据
        dtDis.Columns.Add("containerstepdispatchid");
        ArrayList sqlList = new ArrayList();
        string updateStepInfoSql = "UPDATE CONTAINERSTEPDISPATCH2 C SET C.ISUSE=1 WHERE C.CONTAINERSTEPDISPATCHID = '{0}'";
        string updateStepInfoSql1 = "UPDATE CONTAINERSTEPDISPATCH2 C SET C.ISUSE=1 WHERE C.CONTAINERID='{0}' and C.Workflowstepid = '{1}' and C.stepinfoid = '{2}' and C.ISUSE = 0";
        string updateStepSql = "UPDATE CONTAINERSTEPDISPATCH CSD SET CSD.ISUSE=1 WHERE CSD.CONTAINERID='{0}' and CSD.Workflowstepid = '{1}' and CSD.ISUSE = 0";
        string updateApsDetail = "UPDATE apsplandetail2 ap SET ap.status = 0, ap.lastchangedate = SYSDATE WHERE ap.containerid = '{0}' AND ap.stepinfoid = '{1}'";//更新工步的排产数据
        if (dtContainer.Rows[0]["iscombinate"].ToString() == "1")//如果是合卡批，需删除工步所有派工记录
        {
            DataTable dtMain = dtParam.DefaultView.ToTable(true, "stepinfoid");
            List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();//所有的批次工序
            foreach (DataRow container in dtContainer.Rows)
            {
                string strSql = string.Format(@"SELECT 1 FROM containerstepworkreport2 csw WHERE csw.containerid = '{0}' AND csw.workflowstepid = '{1}' AND csw.isuse = 0", container["containerid"].ToString(), container["workflowstepid"].ToString());
                if (DatabaseHelper.GetSingle(strSql) != null)
                {
                    result.Result = false; result.Message = "存在已报工记录，请撤销报工后刷新页面";
                    break;
                }
                foreach (DataRow dr in dtMain.Rows)
                {
                    //删除工步派工
                    sqlList.Add(string.Format(updateStepInfoSql1, container["containerid"].ToString(), container["workflowstepid"].ToString(), dr["stepinfoid"].ToString()));
                    sqlList.Add(string.Format(updateApsDetail, container["workflowstepid"].ToString(), dr["stepinfoid"].ToString()));//排产回退到未下发
                    string sql = string.Format(@"SELECT csd.containerstepdispatchid 
                                                     FROM containerstepdispatch2 csd 
                                                     WHERE csd.containerid = '{0}' AND csd.workflowstepid = '{1}' AND csd.stepinfoid = '{2}' AND csd.isuse = 0", container["containerid"].ToString(), container["workflowstepid"].ToString(), dr["stepinfoid"].ToString());
                    DataTable dtRes = DatabaseHelper.Query_ReturnDatTable(sql);
                    //添加撤销的派工数据推送到数据中心
                    sqlList.AddRange(commonBusiness.InsertSyncTableChangeRecode(dtRes, "containerstepdispatch2", "containerstepdispatchid", toAppID_RB, 2, false));
                }
                //删除工序派工
                sqlList.Add(string.Format(updateStepSql, container["containerid"].ToString(), container["workflowstepid"].ToString()));
            }
        }
        else
        {
            string strSql = string.Format(@"SELECT 1 FROM containerstepworkreport2 csw WHERE csw.containerid = '{0}' AND csw.workflowstepid = '{1}' AND csw.isuse = 0", dtContainer.Rows[0]["containerid"].ToString(), dtContainer.Rows[0]["workflowstepid"].ToString());
            if (DatabaseHelper.GetSingle(strSql) != null)
            {
                result.Result = false; result.Message = "存在已报工记录，请撤销报工后刷新页面";
            }
            if (result.Result)
            {
                foreach (DataRow dr in dtParam.Rows)
                {
                    //删除工步派工
                    sqlList.Add(string.Format(updateStepInfoSql, dr["containerstepdispatchid"].ToString()));
                    sqlList.Add(string.Format(updateApsDetail, dtContainer.Rows[0]["containerid"].ToString(), dr["stepinfoid"].ToString()));//排产回退到未下发
                }
                sqlList.Add(string.Format(updateStepSql, dtContainer.Rows[0]["containerid"].ToString(), dtContainer.Rows[0]["workflowstepid"].ToString()));
            }
            //添加撤销的派工数据推送到数据中心
            sqlList.AddRange(commonBusiness.InsertSyncTableChangeRecode(dtParam.AsDataView().ToTable(true, "containerstepdispatchid"), "containerstepdispatch2", "containerstepdispatchid", toAppID_RB, 2, false));
        }
        if (result.Result)
        {
            DatabaseHelper.ExecuteSqlTran(sqlList);
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 保存工步报工撤销
    /// </summary>
    /// <param name="context"></param>
    public void SaveStepInfoWorkReportCancel(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "撤销成功" };
        RoleEnum roleEnum = GetRoleLimits();
        if (!(roleEnum == RoleEnum.报工 || roleEnum == RoleEnum.全部))
        {
            result.Result = false; result.Message = "没有该权限";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        DataTable dtContainer = JsonConvert.DeserializeObject<DataTable>(context.Request["container"].ToString());
        DataTable dtParam = JsonConvert.DeserializeObject<DataTable>(context.Request["param"].ToString());
        string containerStepWorkReportIDs = string.Empty;//所有的报工ID
        ArrayList sqlList = new ArrayList();
        //删除工步报工记录sql
        string updateStepInfoSql = "UPDATE containerstepworkreport2 csw SET csw.ISUSE=1 WHERE csw.containerstepworkreportid = '{0}'";
        //删除工序报工记录sql
        string updateStepSql = "UPDATE containerstepworkreport csw SET csw.ISUSE=1 WHERE csw.CONTAINERID='{0}' and csw.Workflowstepid = '{1}' and csw.ISUSE = 0";
        //删除实测值sql
        string deleCheckPointSql = @"delete stepcheckpointresult sc WHERE sc.containerstepworkreportid='{0}' AND sc.containerid='{1}'
                                     and sc.stepcheckpointid IN (select st.stepcheckpointid from stepcheckpoint st where st.workflowstepid='{2}' and st.stepinfoid='{3}')";
        if (dtContainer.Rows[0]["iscombinate"].ToString() == "1")//如果是合卡批，需删除工步所有派工记录
        {
            DataTable dtMain = dtParam.DefaultView.ToTable(true, "stepinfoid");
            foreach (DataRow container in dtContainer.Rows)
            {
                string strSql = string.Format(@"SELECT 1 FROM containercheckinfo2 cc WHERE cc.containerid = '{0}' AND cc.workflowstepid = '{1}' AND cc.isuse = 0", container["containerid"].ToString(), container["workflowstepid"].ToString());
                if (DatabaseHelper.GetSingle(strSql) != null)
                {
                    result.Result = false; result.Message = "存在已检验报工，请撤销检验后刷新页面";
                    break;
                }
                foreach (DataRow dr in dtMain.Rows)
                {
                    //查询批次的该工步所有报工记录，然后删除
                    string sql = string.Format(@"SELECT csw.containerstepworkreportid 
                                 FROM containerstepworkreport2 csw
                                 WHERE csw.containerid = '{0}' AND csw.workflowstepid = '{1}' AND csw.stepinfoid = '{2}' AND csw.isuse = 0",
                                 container["containerid"].ToString(), container["workflowstepid"].ToString(), dr["stepinfoid"].ToString());
                    DataTable dtRes = DatabaseHelper.Query_ReturnDatTable(sql);
                    foreach (DataRow item in dtRes.Rows)
                    {
                        //删除工步报工
                        sqlList.Add(string.Format(updateStepInfoSql, item["containerstepworkreportid"].ToString()));
                        //删除报工实测值
                        sqlList.Add(string.Format(deleCheckPointSql, item["containerstepworkreportid"].ToString(), container["containerid"].ToString(), container["workflowstepid"].ToString(), dr["stepinfoid"].ToString()));
                    }
                }
                //删除工序报工
                sqlList.Add(string.Format(updateStepSql, container["containerid"].ToString(), container["workflowstepid"].ToString()));
            }
        }
        else
        {
            string strSql = string.Format(@"SELECT 1 FROM containercheckinfo2 cc WHERE cc.containerid = '{0}' AND cc.workflowstepid = '{1}' AND cc.isuse = 0", dtContainer.Rows[0]["containerid"].ToString(), dtContainer.Rows[0]["workflowstepid"].ToString());
            if (DatabaseHelper.GetSingle(strSql) != null)
            {
                result.Result = false; result.Message = "存在已检验报工，请撤销检验后刷新页面";
            }
            if (result.Result)
            {
                foreach (DataRow dr in dtParam.Rows)
                {
                    //删除报工
                    sqlList.Add(string.Format(updateStepInfoSql, dr["containerstepworkreportid"].ToString()));
                    //删除报工的实测值
                    sqlList.Add(string.Format(deleCheckPointSql, dr["containerstepworkreportid"].ToString(), dtContainer.Rows[0]["containerid"].ToString(), dtContainer.Rows[0]["workflowstepid"].ToString(), dr["stepinfoid"].ToString()));
                }
                sqlList.Add(string.Format(updateStepSql, dtContainer.Rows[0]["containerid"].ToString(), dtContainer.Rows[0]["workflowstepid"].ToString()));
            }
        }
        if (result.Result)
        {
            DatabaseHelper.ExecuteSqlTran(sqlList);
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 保存工步检验撤销
    /// </summary>
    /// <param name="context"></param>
    public void SaveStepInfoCheckCancel(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "撤销成功" };
        RoleEnum roleEnum = GetRoleLimits();
        if (!(roleEnum == RoleEnum.检验 || roleEnum == RoleEnum.全部))
        {
            result.Result = false; result.Message = "没有该权限";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        DataTable dtContainer = JsonConvert.DeserializeObject<DataTable>(context.Request["container"].ToString());
        DataTable dtCheck = JsonConvert.DeserializeObject<DataTable>(context.Request["check"].ToString());
        if (dtCheck.Rows.Count == 0)
        {
            result.Result = false; result.Message = "未选择工步";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        string stepInfoID = dtCheck.Rows[0]["stepInfoID"].ToString();
        string stepSeq = dtCheck.Rows[0]["stepSeq"].ToString();
        if (dtCheck.AsEnumerable().Where(p => p["StepInfoID"].ToString() != stepInfoID).Count() > 0)
        {
            result.Result = false; result.Message = "只能选择同一工步";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        //开始撤销
        if (dtContainer.Rows[0]["iscombinate"].ToString() == "1") //如果是合卡批次
        {
            string sql = string.Empty;
            ArrayList sqlList = new ArrayList();
            List<Dictionary<string, string>> lossDicList = new List<Dictionary<string, string>>();//批次报废记录
            foreach (DataRow container in dtContainer.Rows)
            {
                //验证是否存在更高顺序号工步
                sql = string.Format(@"
                      SELECT 1 FROM containercheckinfo2 cci 
                      LEFT JOIN stepinfo s ON s.stepinfoid = cci.stepinfoid
                      WHERE cci.containerid = '{0}' AND cci.workflowstepid = '{1}' AND cci.isuse = 0 AND s.stepseq > {2}", container["containerid"].ToString(), container["WorkflowStepID"].ToString(), stepSeq);
                if (DatabaseHelper.GetSingle(sql) != null)
                {
                    result.Result = false; result.Message = "存在更高顺序号的工步，不可跨工步撤销";
                    break;
                }
                //查询批次的工步检验信息
                sql = string.Format(@"SELECT SUM(nvl(cci.checkqty,0)) checkqty,SUM(nvl(cci.lossqty,0)) lossqty 
                    ,to_char(wm_concat(cci.containercheckinfoid)) containercheckinfoids
                    FROM containercheckinfo2 cci 
                    WHERE cci.stepinfoid = '{0}' AND cci.workflowstepid = '{1}' AND cci.containerid = '{2}' AND cci.isuse = 0
                    GROUP BY cci.stepinfoid", stepInfoID, container["WorkflowStepID"].ToString(), container["containerid"].ToString());
                DataTable dtStepInfoCheckQty = DatabaseHelper.Query_ReturnDatTable(sql);
                if (dtStepInfoCheckQty.Rows.Count == 0)//如果没有检验记录，则跳过
                {
                    continue;
                }
                int lossQty = int.Parse(dtStepInfoCheckQty.Rows[0]["lossqty"].ToString());
                string containerCheckInfoIds = containerCheckInfoIds = string.Format("'{0}'", dtStepInfoCheckQty.Rows[0]["containercheckinfoids"].ToString().Replace(",", "','"));
                //删除工步检验记录
                sql = string.Format(@"UPDATE containercheckinfo2 cci SET cci.isuse = 1 WHERE cci.containerid = '{0}' AND cci.workflowstepid = '{1}' AND cci.stepinfoid = '{2}'", container["containerid"].ToString(), container["WorkflowStepID"].ToString(), stepInfoID);
                sqlList.Add(sql);
                if (lossQty > 0) //如果该批次的工步存在报废，则更改报工报废信息
                {
                    sql = string.Format(@"UPDATE containercurrentinfo c SET c.alllossqty = NVL(c.alllossqty,0) - {0} WHERE c.containerid = '{1}'", lossQty, container["containerid"].ToString());
                    sqlList.Add(sql);
                    sql = string.Format(@"UPDATE containerstepworkreport2 csw SET csw.lossqty = 0 WHERE csw.containerid = '{0}' AND csw.workflowstepid = '{1}' AND csw.stepinfoid = '{2}'", container["containerid"].ToString(), container["WorkflowStepID"].ToString(), stepInfoID);
                    sqlList.Add(sql);
                    sql = "select ch.checkqtychangerecordid,ch.containerid,ch.qty from checkqtychangerecord ch where ch.containercheckinfoid IN ({0}) and ch.stepinfoid = '{1}' and ch.isuse = 0";
                    sql = string.Format(sql, containerCheckInfoIds, stepInfoID);
                    DataTable dtChange = DatabaseHelper.Query_ReturnDatTable(sql);
                    foreach (DataRow item in dtChange.Rows)
                    {
                        sql = "UPDATE checkqtychangerecord ccr SET ccr.isuse = 1 WHERE ccr.checkqtychangerecordid = '" + item["checkqtychangerecordid"].ToString() + "'";
                        sqlList.Add(sql);
                        if (container["ContainerType"].ToString() == "3")
                        {
                            sql = "update container c1 set c1.status=1,c1.qty=c1.qty+({0}) where c1.containerid='{1}'";
                            sql = string.Format(sql, Math.Abs(int.Parse(item["qty"].ToString())), item["containerid"].ToString());
                            sqlList.Add(sql);
                        }
                    }
                }
                // 撤销工序检验记录
                sql = "UPDATE containercheckinfo cci1 SET cci1.isuse = 1 WHERE cci1.containerid = '{0}' AND cci1.workflowstepid = '{1}' AND cci1.isuse = 0";
                sql = string.Format(sql, container["ContainerID"].ToString(), container["WorkflowStepID"].ToString());
                sqlList.Add(sql);
                // 如果工步已经检验完成，且有报废数，则要更改批次在制数
                if (lossQty > 0)
                {
                    lossDicList.Add(new Dictionary<string, string>() { 
                                    {"ContainerID",container["ContainerID"].ToString()},
                                    {"LossQty",lossQty.ToString()}
                    });
                }
            }
            if (result.Result)
            {
                //最终执行SQL
                DatabaseHelper.ExecuteSqlTran(sqlList);
                foreach (Dictionary<string, string> item in lossDicList)
                {
                    containerBusiness.ChangeContainerQty(item["ContainerID"], int.Parse(item["LossQty"]));
                }
            }
        }
        else
        {
            result = checkBusiness.SaveStepInfoCheckCancel(dtCheck);
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 获取未派工的批次（热表）
    /// </summary>
    /// <param name="context"></param>
    public void GetRBUnDispatchContainerDataList(HttpContext context)
    {
        StringBuilder sql = new StringBuilder();
        sql.AppendFormat(@"SELECT Distinct to_char(wm_concat(cc.containername)) facontainername,ci.mfgordername,
                        ci.containername,ci.containerid,ci.productid,ci.workflowid,ci.workflowstepid,ci.workflowstepname,
                        c.rbtogetherflag,ci.qty,c.originalstartdate CREATEDATE,
                        ci.workflowname || ':'||ci.workflowrevision workflownameandrev,ci.productname || ':' || ci.productrevision productnameandrev,
                        '' combinatename,'' containercombinateid
                        FROM containercurrentinfo ci
                        LEFT JOIN container c ON c.containerid = ci.containerid
                        LEFT JOIN containersubcontainer csc ON csc.subcontainerid = c.containerid
                        LEFT JOIN container cc ON cc.containerid = csc.containerid
                        LEFT JOIN containershiprecord csr ON csr.containerid = cc.containerid AND csr.isuse = 0 AND csr.toacceptdate IS NOT NULL
                        LEFT JOIN containershiprecordstep csrs ON csrs.containershiprecordid = csr.containershiprecordid 
                        LEFT JOIN workflowstep ws ON ws.workflowstepid = csrs.workflowstepid 
                        WHERE cc.containertype = '7' AND nvl(c.rbtogetherflag,'0')!='0' AND c.status =1 AND ci.isinstore = 0 
                        AND (ws.workflowstepid = csc.workflowstepid OR ws.workflowstepname = csc.workflowstepname) --只查询转工接收的
                        AND NOT EXISTS (SELECT 1 FROM containerstepdispatch2 csd WHERE csd.containerid = ci.containerid AND csd.isuse = 0) --没有工步派工记录
                        AND NOT EXISTS (SELECT 1 FROM containerstepdispatch csd WHERE csd.containerid = ci.containerid AND csd.isuse = 0) --没有工序派工记录
                        AND NOT EXISTS (SELECT 1 FROM containercombinate ccb WHERE ccb.containerid = ci.containerid) --没有合卡
                        AND csc.containersubcontainerid IS NOT NULL --只查询转工子卡
                        AND c.originalfactoryid = '{0}'", m_UserInfo.FactoryID);
        if (!string.IsNullOrWhiteSpace(context.Request["orderName"].ToString()))
        {
            sql.AppendFormat(" AND ci.mfgordername = '{0}'", context.Request["orderName"].ToString());
        }
        if (!string.IsNullOrWhiteSpace(context.Request["productName"].ToString()))
        {
            sql.AppendFormat(" AND ci.productname like '{0}%'", context.Request["productName"].ToString());
        }
        sql.Append(@" GROUP BY ci.mfgordername,ci.containername,ci.containerid,ci.productid,ci.workflowid,ci.workflowstepid,ci.workflowstepname,
                        c.rbtogetherflag,ci.qty,c.originalstartdate,ci.workflowname,ci.workflowrevision,ci.productname, ci.productrevision
                        ORDER BY ci.containername,c.rbtogetherflag");
        uMESPagingDataDTO paraPage = new uMESPagingDataDTO();
        paraPage.CurrentPageIndex = Convert.ToInt32(context.Request.Form["pageIndex"].ToString());//页码
        paraPage.PageSize = Convert.ToInt32(context.Request.Form["PageSize"].ToString());//每页页数
        paraPage.strSQL = sql.ToString();
        uMESProcessResult result = DatabaseHelper.RunProcedureForPage(paraPage);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 获取已派工但未报工的批次（热表）
    /// </summary>
    /// <param name="context"></param>
    public void GetRBDispatchContainerDataList(HttpContext context)
    {
        StringBuilder sql = new StringBuilder();
        sql.AppendFormat(@"SELECT Distinct to_char(wm_concat(cc.containername)) facontainername,ci.mfgordername,
                        ci.containername,ci.containerid,ci.productid,ci.workflowid,ci.workflowstepid,ci.workflowstepname,
                        c.rbtogetherflag,ci.qty,c.originalstartdate CREATEDATE,
                        ci.workflowname || ':'||ci.workflowrevision workflownameandrev,ci.productname || ':' || ci.productrevision productnameandrev,
                        '' combinatename,'' containercombinateid
                        FROM containercurrentinfo ci
                        LEFT JOIN container c ON c.containerid = ci.containerid
                        LEFT JOIN containersubcontainer csc ON csc.subcontainerid = c.containerid
                        LEFT JOIN container cc ON cc.containerid = csc.containerid
                        LEFT JOIN containershiprecord csr ON csr.containerid = cc.containerid AND csr.isuse = 0 AND csr.toacceptdate IS NOT NULL
                        LEFT JOIN containershiprecordstep csrs ON csrs.containershiprecordid = csr.containershiprecordid 
                        LEFT JOIN workflowstep ws ON ws.workflowstepid = csrs.workflowstepid 
                        WHERE cc.containertype = '7' AND nvl(c.rbtogetherflag,'0')!='0' AND c.status =1 AND ci.isinstore = 0 
                        AND (ws.workflowstepid = csc.workflowstepid OR ws.workflowstepname = csc.workflowstepname) --只查询转工接收的
                        AND EXISTS (SELECT 1 FROM containerstepdispatch csd WHERE csd.containerid = ci.containerid AND csd.isuse = 0) --存在工序派工记录
                        AND NOT EXISTS (SELECT 1 FROM containerstepworkreport2 csw WHERE csw.containerid = ci.containerid AND csw.isuse = 0) --没有工步报工记录
                        AND NOT EXISTS (SELECT 1 FROM containercombinate ccb WHERE ccb.containerid = ci.containerid) --没有合卡
                        AND csc.containersubcontainerid IS NOT NULL --只查询转工子卡
                        AND c.originalfactoryid = '{0}'", m_UserInfo.FactoryID);
        if (!string.IsNullOrWhiteSpace(context.Request["orderName"].ToString()))
        {
            sql.AppendFormat(" AND ci.mfgordername = '{0}'", context.Request["orderName"].ToString());
        }
        if (!string.IsNullOrWhiteSpace(context.Request["productName"].ToString()))
        {
            sql.AppendFormat(" AND ci.productname like '{0}%'", context.Request["productName"].ToString());
        }
        sql.Append(@" GROUP BY ci.mfgordername,ci.containername,ci.containerid,ci.productid,ci.workflowid,ci.workflowstepid,ci.workflowstepname,
                        c.rbtogetherflag,ci.qty,c.originalstartdate,ci.workflowname,ci.workflowrevision,ci.productname, ci.productrevision
                        ORDER BY ci.containername,c.rbtogetherflag");
        uMESPagingDataDTO paraPage = new uMESPagingDataDTO();
        paraPage.CurrentPageIndex = Convert.ToInt32(context.Request.Form["pageIndex"].ToString());//页码
        paraPage.PageSize = Convert.ToInt32(context.Request.Form["PageSize"].ToString());//每页页数
        paraPage.strSQL = sql.ToString();
        uMESProcessResult result = DatabaseHelper.RunProcedureForPage(paraPage);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 获取合卡的数据列表（热表）
    /// </summary>
    /// <param name="context"></param>
    public void GetRBContainerCombinateDataList(HttpContext context)
    {
        StringBuilder sql = new StringBuilder();
        sql.AppendFormat(@"SELECT * FROM (SELECT Distinct ci.mfgordername,ci.productid,ci.workflowid,ci.workflowstepid,ci.workflowstepname,ci.qty,c.rbtogetherflag,
                        ci.workflowname || ':'||ci.workflowrevision workflownameandrev,ci.productname || ':' || ci.productrevision productnameandrev,ccb.containercombinatename combinatename
                        ,ccb.combinateno
                        FROM containercombinate ccb 
                        LEFT JOIN containercurrentinfo ci on ci.containerid = ccb.containerid
                        LEFT JOIN container c ON c.containerid = ci.containerid
                        where ci.isinstore = {0}", int.Parse(context.Request["isInstore"].ToString()));
        if (!string.IsNullOrWhiteSpace(context.Request["orderName"].ToString()))
        {
            sql.AppendFormat(" AND ci.mfgordername = '{0}'", context.Request["orderName"].ToString());
        }
        if (!string.IsNullOrWhiteSpace(context.Request["productName"].ToString()))
        {
            sql.AppendFormat(" AND ci.productname like '{0}%'", context.Request["productName"].ToString());
        }
        sql.Append(@")k ORDER BY k.combinateno DESC");
        uMESPagingDataDTO paraPage = new uMESPagingDataDTO();
        paraPage.CurrentPageIndex = Convert.ToInt32(context.Request.Form["pageIndex"].ToString());//页码
        paraPage.PageSize = Convert.ToInt32(context.Request.Form["PageSize"].ToString());//每页页数
        paraPage.strSQL = sql.ToString();
        uMESProcessResult result = DatabaseHelper.RunProcedureForPage(paraPage);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private enum CombinateType { 未派工 = 0, 已派工 = 1 }
    /// <summary>
    /// 保存合批数据
    /// </summary>
    /// <param name="context"></param>
    public void SaveContainerCombinateData(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        CombinateType optype = (CombinateType)int.Parse(context.Request.Form["optype"].ToString());
        DataTable dtContainer = JsonConvert.DeserializeObject<DataTable>(context.Request.Form["container"].ToString());
        if (dtContainer.Rows.Count == 0)
        {
            result.Result = false; result.Message = "未选择数据";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        if (dtContainer.DefaultView.ToTable(true, "mfgordername", "productid", "workflowid", "workflowstepid", "rbtogetherflag", "qty").Rows.Count > 1)
        {
            result.Result = false; result.Message = "存在不同类型的批次";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        lock (obj)
        {
            switch (optype)
            {
                case CombinateType.未派工:
                    result = UnDispatchCombinateVaild(dtContainer);
                    break;
                case CombinateType.已派工:
                    result = DispatchCombinateVaild(dtContainer);
                    break;
                default:
                    result.Result = false; result.Message = "参数出错";
                    break;
            }
            if (result.Result)
            {
                //获取最新的合卡编号
                string sql = "SELECT MAX(combinateno) combinateno FROM containercombinate";
                DataTable res = DatabaseHelper.Query_ReturnDatTable(sql);
                int combinateno = string.IsNullOrWhiteSpace(res.Rows[0]["combinateno"].ToString()) ? 1 : int.Parse(res.Rows[0]["combinateno"].ToString()) + 1;
                string combinatename = dtContainer.Rows[0]["rbtogetherflag"].ToString() + "H" + combinateno;
                //查询是否重复
                sql = string.Format("SELECT 1 FROM containercombinate ccb where ccb.containercombinatename = '{0}'", combinatename);
                if (DatabaseHelper.GetSingle(sql) != null)
                {
                    context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "合卡名重复，请重新查询" }));
                    return;
                }
                ArrayList sqlList = new ArrayList();
                sql = @"INSERT INTO containercombinate(containercombinateid,containercombinatename,combinateno,containerid,containername,createdate,createemployeeid,factoryid) 
                VALUES('{0}','{1}',{2},'{3}','{4}',sysdate,'{5}','{6}')";
                dtContainer.AsEnumerable().ToList().ForEach(p =>
                {
                    if (!sqlList.Contains(p["containerid"].ToString()))
                    {
                        sqlList.Add(string.Format(sql, Guid.NewGuid().ToString(), combinatename, combinateno, p["containerid"].ToString(), p["containername"].ToString(), m_UserInfo.EmployeeID, m_UserInfo.FactoryID));
                    }
                });
                DatabaseHelper.ExecuteSqlTran(sqlList);
                result.Message = "保存成功";
            }
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }
    /// <summary>
    /// 未派工合卡验证
    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    private uMESProcessResult UnDispatchCombinateVaild(DataTable dt)
    {
        uMESProcessResult res = new uMESProcessResult() { Result = true };
        string sql = string.Empty;
        foreach (DataRow item in dt.Rows)
        {
            sql = string.Format(@"SELECT 1 FROM containercombinate c WHERE c.containerid = '{0}'", item["containerid"].ToString());
            if (DatabaseHelper.GetSingle(sql) != null)
            {
                res.Result = false; res.Message = string.Format("批次：{0}已合批，请重新查询", item["containername"].ToString());
            }
            sql = string.Format(@"SELECT 1 FROM containerstepdispatch2 csd WHERE csd.containerid = '{0}' AND csd.isuse = 0", item["containerid"].ToString());
            if (DatabaseHelper.GetSingle(sql) != null)
            {
                res.Result = false; res.Message = string.Format("批次：{0}已派工，请重新查询", item["containername"].ToString());
                break;
            }
            sql = string.Format(@"SELECT 1 FROM containerstepdispatch csd WHERE csd.containerid = '{0}' AND csd.isuse = 0", item["containerid"].ToString());
            if (DatabaseHelper.GetSingle(sql) != null)
            {
                res.Result = false; res.Message = string.Format("批次：{0}已派工，请重新查询", item["containername"].ToString());
                break;
            }
        }
        return res;
    }

    /// <summary>
    /// 已派工合卡验证
    /// </summary>
    /// <param name="dt"></param>
    /// <returns></returns>
    private uMESProcessResult DispatchCombinateVaild(DataTable dt)
    {
        uMESProcessResult res = new uMESProcessResult() { Result = true };
        string sql = string.Empty;
        string workflowstepID = dt.Rows[0]["workflowstepid"].ToString();
        foreach (DataRow item in dt.Rows)
        {
            sql = string.Format(@"SELECT 1 FROM containercombinate c WHERE c.containerid = '{0}'", item["containerid"].ToString());
            if (DatabaseHelper.GetSingle(sql) != null)
            {
                res.Result = false; res.Message = string.Format("批次：{0}已合批，请重新查询", item["containername"].ToString()); break;
            }
            sql = string.Format(@"SELECT 1 FROM containerstepworkreport2 csw WHERE csw.containerid = '{0}' AND csw.isuse = 0", item["containerid"].ToString());
            if (DatabaseHelper.GetSingle(sql) != null)
            {
                res.Result = false; res.Message = string.Format("批次：{0}存在已报工，请重新查询", item["containername"].ToString());
                break;
            }
            sql = string.Format(@"SELECT 1 FROM containerstepdispatch csd WHERE csd.containerid = '{0}' AND csd.isuse = 0", item["containerid"].ToString());
            if (DatabaseHelper.GetSingle(sql) == null)
            {
                res.Result = false; res.Message = string.Format("批次：{0}存在未派工，请重新查询", item["containername"].ToString());
                break;
            }
            sql = string.Format(@"SELECT 1 FROM (
                                    SELECT SUM(nvl(csd.qty,0)) disqty,c.qty FROM containercurrentinfo c 
                                    LEFT JOIN stepinfo s ON s.workflowstepid = c.workflowstepid
                                    LEFT JOIN containerstepdispatch2 csd ON csd.containerid = c.containerid AND csd.stepinfoid = s.stepinfoid AND csd.isuse = 0
                                    WHERE c.containerid = '{0}'
                                    GROUP BY s.stepinfoid,c.qty
                                    )k WHERE k.disqty < k.qty", item["containerid"].ToString());
            if (DatabaseHelper.GetSingle(sql) != null)
            {
                res.Result = false; res.Message = string.Format("批次：{0}存在未派完工（工步），请重新查询", item["containername"].ToString());
                break;
            }
        }
        if (res.Result)
        {
            //验证报工人是否一致
            sql = string.Format("SELECT s.stepinfoid,s.stepno,s.description FROM stepinfo s WHERE s.workflowstepid = '{0}'", workflowstepID);
            DataTable dtStepInfo = DatabaseHelper.Query_ReturnDatTable(sql);//查询出所有工步
            foreach (DataRow stepInfo in dtStepInfo.Rows)
            {
                string workerIDs = string.Empty;
                sql = @"SELECT to_char(wm_concat(CASE WHEN csd.workerid IS NULL THEN csdd.workerid ELSE csd.workerid END)) workerids FROM containerstepdispatch2 csd 
                    LEFT JOIN containerstepdispatchdetail2 csdd ON csdd.containerstepdispatchid = csd.containerstepdispatchid
                    WHERE csd.stepinfoid = '{0}' AND csd.containerid = '{1}' AND csd.isuse = 0";
                foreach (DataRow item in dt.Rows)
                {
                    DataTable dtRes = DatabaseHelper.Query_ReturnDatTable(string.Format(sql, stepInfo["stepinfoid"].ToString(), item["containerid"].ToString()));
                    if (string.IsNullOrWhiteSpace(dtRes.Rows[0]["workerids"].ToString()))
                    {
                        res.Result = false; res.Message = string.Format("批次：{0}的工步：{1}存在没有指定报工人的派工", item["containername"].ToString(), string.Format("{0}-{1}", stepInfo["stepno"].ToString(), stepInfo["description"].ToString())); break;
                    }
                    if (!string.IsNullOrWhiteSpace(workerIDs) && workerIDs != dtRes.Rows[0]["workerids"].ToString())
                    {
                        res.Result = false; res.Message = string.Format("批次：{0}的工步：{1}的派工存在不一致的报工人", item["containername"].ToString(), string.Format("{0}-{1}", stepInfo["stepno"].ToString(), stepInfo["description"].ToString())); break;
                    }
                    workerIDs = dtRes.Rows[0]["workerids"].ToString();
                }
                if (!res.Result)
                {
                    break;
                }
            }
        }
        return res;
    }

    /// <summary>
    /// 删除合卡数据
    /// </summary>
    /// <param name="context"></param>
    public void DeleContainerCombinateData(HttpContext context)
    {
        if (GetRoleLimits() != RoleEnum.全部)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "抱歉，你没有权限" }));
            return;
        }
        DataTable dtNames = JsonConvert.DeserializeObject<DataTable>(context.Request.Form["combinatename"].ToString());
        if (dtNames.Rows.Count == 0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "未选择数据" }));
            return;
        }
        string names = string.Empty;
        dtNames.AsEnumerable().ToList().ForEach(c =>
        {
            if (!names.Contains(c["combinatename"].ToString()))
            {
                names += string.Format("'{0}',", c["combinatename"]);
            }
        });
        names = names.TrimEnd(',');
        string sql = string.Format("DELETE containercombinate cb WHERE cb.containercombinatename IN ({0})", names);
        DatabaseHelper.ExecuteSql(sql);
        //        string sql = string.Format(@"SELECT csd.containerstepdispatchid FROM containercombinate cb 
        //                LEFT JOIN containerstepdispatch2 csd on csd.containerid = cb.containerid AND csd.isuse = 0
        //                WHERE cb.containercombinatename IN ({0})", names);
        //        DataTable dtRes = DatabaseHelper.Query_ReturnDatTable(sql);
        //        if (dtRes.Rows.Count > 0)
        //        {
        //            if (dtRes.AsEnumerable().Where(p => !string.IsNullOrWhiteSpace(p["containerstepdispatchid"].ToString())).Count() > 0)
        //            {
        //                context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "存在派工记录" }));
        //                return;
        //            }
        //            sql = string.Format("DELETE containercombinate cb WHERE cb.containercombinatename IN ({0})", names);
        //            DatabaseHelper.ExecuteSql(sql);
        //        }

        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "删除成功" }));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}